home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
MACD 5
/
MACD 5.bin
/
workbench
/
libs
/
intuisup.lha
/
Intuisup
/
source.lha
/
Menus
/
menus_test.c
< prev
next >
Wrap
C/C++ Source or Header
|
1992-07-28
|
7KB
|
217 lines
/* $Revision Header *** Header built automatically - do not edit! ***********
*
* (C) Copyright 1991 by Torsten Jürgeleit
*
* Name .....: menus_test.c
* Created ..: Thursday 19-Dec-91 18:03:07
* Revision .: 2
*
* Date Author Comment
* ========= ==================== ====================
* 11-Jul-92 Torsten Jürgeleit now get pointer to console device
* 03-Jun-92 Torsten Jürgeleit alternate color for menu item texts
* 19-Dec-91 Torsten Jürgeleit Created this file!
*
****************************************************************************
*
* Test of menu support functions
*
* $Revision Header ********************************************************/
/* Includes */
#include <exec/types.h>
#include <graphics/gfxbase.h>
#include <graphics/text.h>
#include <intuition/intuitionbase.h>
#include <intuition/intuition.h>
#ifdef AZTEC_C
#include <functions.h> /* needed for Aztec C - prototypes and pragmas for all Amiga system functions */
#endif
#include <libraries/memwatch.h> /* header file for memory debug link library (Fish 240) - AFTER functions.h */
#include "/render/render.h"
#include "/texts/texts.h"
#include "menus.h"
/* Defines */
#define WINDOW_WIDTH 600
#define WINDOW_HEIGHT 180
#define WINDOW_IDCMP (CLOSEWINDOW | MENUPICK)
#define WINDOW_FLAGS (WINDOWCLOSE | WINDOWDRAG | WINDOWDEPTH | SMART_REFRESH | NOCAREREFRESH | ACTIVATE)
#define WINDOW_TITLE (UBYTE *)" Menus test "
#define RENDER_INFO_FLAGS (USHORT)(RENDER_INFO_FLAG_INNER_WINDOW | RENDER_INFO_FLAG_BACK_FILL)
#define OPEN_WINDOW_FLAGS (USHORT)(OPEN_WINDOW_FLAG_CENTER_SCREEN | OPEN_WINDOW_FLAG_RENDER_PENS)
#define MESSAGE1_TEXT "Select menu item"
#define MESSAGE1_TOP_EDGE 60
#define MESSAGE1_TEXT_ATTR &topaz60_attr
#define MESSAGE2_TEXT "Menu no. %d menu item no. %d sub item no. %d selected"
#define MESSAGE2_TOP_EDGE 120
#define MESSAGE2_TEXT_ATTR &topaz80_attr
/* Globals */
struct IntuitionBase *IntuitionBase;
struct GfxBase *GfxBase;
struct Library *DiskfontBase;
struct Library *LayersBase;
struct Device *ConsoleDevice;
/* Statics */
STATIC struct NewWindow test_new_window = {
0, 0, WINDOW_WIDTH, WINDOW_HEIGHT, 0, 0, WINDOW_IDCMP, WINDOW_FLAGS,
NULL, NULL, WINDOW_TITLE, NULL, NULL, 0, 0, 0, 0, WBENCHSCREEN
};
STATIC struct TextAttr topaz80_attr = { (STRPTR)"topaz.font", TOPAZ_EIGHTY,
FS_NORMAL, FPF_ROMFONT },
topaz60_attr = { (STRPTR)"topaz.font", TOPAZ_SIXTY,
FS_NORMAL, FPF_ROMFONT };
/* Defines for test menus */
#define TEST_MENU_TEXT_ATTR &topaz60_attr
/* Statics for test menus */
STATIC struct MenuData test_menu_data[] = {
{
MENU_DATA_TYPE_TITLE, 0, "Menu 0", NULL, 0
}, {
MENU_DATA_TYPE_ITEM, MENU_DATA_FLAG_ATTRIBUTE | MENU_DATA_FLAG_SELECTED, "Item 0.0", "0", ~(1L << 0)
}, {
MENU_DATA_TYPE_ITEM, MENU_DATA_FLAG_ATTRIBUTE, "Item 0.1", "1", ~(1L << 1)
}, {
MENU_DATA_TYPE_ITEM, MENU_DATA_FLAG_HIGH_BOX, "Item 0.2", NULL, 0
}, {
MENU_DATA_TYPE_SUBITEM, 0, "Item 0.2.0", "A", 0
}, {
MENU_DATA_TYPE_SUBITEM, 0, "Item 0.2.1", "B", 0
}, {
MENU_DATA_TYPE_ITEM, MENU_DATA_FLAG_TEXT_COLOR2, "Item 0.3", NULL, 0
}, {
MENU_DATA_TYPE_TITLE, 0, "Menu 1", NULL, 0
}, {
MENU_DATA_TYPE_ITEM, MENU_DATA_FLAG_HIGH_BOX, "Item 1.0", "C", 0
}, {
MENU_DATA_TYPE_ITEM, MENU_DATA_FLAG_EMPTY_LINE, "Item 1.1", "D", 0
}, {
MENU_DATA_TYPE_ITEM, 0, "Item 1.2", NULL, 0
}, {
MENU_DATA_TYPE_SUBITEM, 0, "Item 1.2.0", "E", 0
}, {
MENU_DATA_TYPE_SUBITEM, 0, "Item 1.2.1", "F", 0
}, {
MENU_DATA_TYPE_ITEM, 0, "Item 1.3", NULL, 0
}, {
MENU_DATA_TYPE_SUBITEM, 0, "Item 1.3.0", "G", 0
}, {
MENU_DATA_TYPE_SUBITEM, MENU_DATA_FLAG_EMPTY_LINE, "Item 1.3.1", "H", 0
}, {
MENU_DATA_TYPE_ITEM, MENU_DATA_FLAG_TEXT_COLOR2, "Item 1.4", "I", 0
}, {
INTUISUP_DATA_END /* mark end of menu data */
}
};
/* Prototypes */
VOID test_action(struct RenderInfo *ri, struct Window *win,
struct MenuList *ml);
/* Pragmas */
#pragma regcall(test_action(a0,a1,a2))
/* Menus test */
LONG
main(VOID)
{
struct IOStdReq io;
struct RenderInfo *ri;
struct Window *win;
struct MenuList *ml;
MWInit((BPTR)NULL, 0L);
if (IntuitionBase = OpenLibrary("intuition.library", 0L)) {
if (GfxBase = OpenLibrary("graphics.library", 0L)) {
if (DiskfontBase = OpenLibrary("diskfont.library", 0L)) {
if (LayersBase = OpenLibrary("layers.library", 0L)) {
if (!OpenDevice("console.device", -1L,
(struct IORequest *)&io, 0L)) {
ConsoleDevice = io.io_Device;
if (ri = get_render_info(NULL, RENDER_INFO_FLAGS)) {
if (win = open_window(ri, &test_new_window,
OPEN_WINDOW_FLAGS)) {
print_text(ri, win, MESSAGE1_TEXT, 0,
MESSAGE1_TOP_EDGE, TEXT_DATA_TYPE_TEXT,
TEXT_DATA_FLAG_CENTER, MESSAGE2_TEXT_ATTR);
if (ml = create_menu(ri, win, &test_menu_data[0],
TEST_MENU_TEXT_ATTR, NULL)) {
attach_menu(win, ml);
test_action(ri, win, ml);
remove_menu(ml);
free_menu(ml);
}
close_window(win, FALSE);
}
free_render_info(ri);
}
CloseDevice((struct IORequest *)&io);
}
CloseLibrary(LayersBase);
}
CloseLibrary(DiskfontBase);
}
CloseLibrary(GfxBase);
}
CloseLibrary(IntuitionBase);
}
MWTerm();
return(0L);
}
/* Perform IDCMP action */
VOID
test_action(struct RenderInfo *ri, struct Window *win, struct MenuList *ml)
{
struct MsgPort *up = win->UserPort;
BOOL keepon = TRUE;
do {
struct IntuiMessage *msg;
WaitPort(up);
while (msg = (struct IntuiMessage *)GetMsg(up)) {
ULONG class = msg->Class;
USHORT code = msg->Code;
ReplyMsg((struct Message *)msg);
switch (class) {
case CLOSEWINDOW :
keepon = FALSE;
break;
case MENUPICK :
while (code != MENUNULL) {
BYTE buffer[80];
sprintf(&buffer[0], MESSAGE2_TEXT,
(MENUNUM(code) != NOMENU ? MENUNUM(code) : 0),
(ITEMNUM(code) != NOITEM ? ITEMNUM(code) : 0),
(SUBNUM(code) != NOSUB ? SUBNUM(code) : 0));
clear_window(ri, win, 0, MESSAGE2_TOP_EDGE, WINDOW_WIDTH,
10, 0);
print_text(ri, win, &buffer[0], 0, MESSAGE2_TOP_EDGE,
TEXT_DATA_TYPE_TEXT, TEXT_DATA_FLAG_CENTER |
TEXT_DATA_FLAG_COLOR2, MESSAGE2_TEXT_ATTR);
code = menu_item_address(ml, code)->NextSelect;
}
break;
}
}
} while (keepon == TRUE);
}